﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using utils;

namespace dal.cgm_production_dao
{
    [DataContract]
    public class SensorCoverInfo
    {
        [DataMember]
        public int id { get; set; }
        [DataMember]
        public string batch_id { get; set; }
        [DataMember]
        public string cover_code { get; set; }
        [DataMember]
        public DateTime create_time { get; set; }
        [DataMember]
        public DateTime update_time { get; set; }
        [DataMember]
        public int is_bind_sensor { get; set; }
    }

    public static class SensorCoverInfoDao
    {
        public static SensorCoverInfo GetCoverInfo(string coverInfo)
        {
            // SQL 查询中使用 @coverInfo
            string sql = @"SELECT id, batch_id, cover_code, create_time, update_time, is_bind_sensor FROM cover_info WHERE cover_code = @coverInfo";
            List<MySqlParameter> parameters = new List<MySqlParameter>();
            // 确保参数名称一致
            parameters.Add(new MySqlParameter("@coverInfo", coverInfo)); // 改为 @coverInfo

            DataSet ds = MySqlHelper.ExecuteDataset(ConfigString.cgm_production, sql, parameters.ToArray());

            IList<SensorCoverInfo> list = DataContainerUtil.DataTableToList<SensorCoverInfo>(ds.Tables[0]);
            if (list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return new SensorCoverInfo();
            }
        }
    }
}
